﻿using AutoMapper;
using System.Collections.Generic;
using Avalon.Core.MVC.StateBags;
using System.Linq;

namespace Avalon.Core.MVC.Actions
{
    //public sealed class ModelConverter<TViewModel, TModel> where TModel : class
    //{
    //    private readonly IContextEntityBag<TViewModel, TModel> _bag;

    //    public ModelConverter(IContextEntityBag<TViewModel, TModel> bag)
    //    {
    //        _bag = bag;
    //    }

    //    public void Execute(ConvertionOptions pOptions)
    //    {
    //        switch (pOptions)
    //        {
    //            case ConvertionOptions.ModelToViewModel:
    //                _bag.ViewModel = Mapper.Map<TViewModel>(_bag.Model);
    //                break;
    //            case ConvertionOptions.ViewModelToModel:
    //                if (_bag.Model == null) _bag.Model = Mapper.Map<TModel>(_bag.ViewModel);
    //                else Mapper.Map<TViewModel, TModel>(_bag.ViewModel, _bag.Model);
    //                break;
    //            case ConvertionOptions.ModelsToViewModels:
    //                _bag.ViewModels = Mapper.Map<IEnumerable<TViewModel>>(_bag.Models);
    //                break;
    //            case ConvertionOptions.ViewModelsToModels:
    //                _bag.Models = Mapper.Map<IEnumerable<TModel>>(_bag.ViewModels).AsQueryable();
    //                break;
    //        }
    //    }
    //}

    //public enum ConvertionOptions
    //{
    //    ModelToViewModel,
    //    ViewModelToModel,
    //    ModelsToViewModels,
    //    ViewModelsToModels
    //}
}